import javax.swing.tree.TreeNode;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:二叉树中序非递归遍历实现
 * User: liangyuanzhang
 * Date: 2025-4-30
 * Time: 0:18
 */
public class InOrderNor {

    public void preOrderNor(TreeNode root) {
        if (root == null) return;
        Stack<TreeNode> stack = new Stack<>();
        TreeNode cur = root;

        while (cur != null || !stack.isEmpty()) {
            while (cur != null) {
                stack.push(cur);
                cur = cur.left;
            }
            TreeNode top = stack.pop();
            System.out.print(cur.val + " ");
            cur = top.right;
        }
    }

}
